/*
  Optimal control problem
  purpose: Definition of cost function, constraints and callback for the KNITRO optimization toolbox
  Jan Stebel
*/

#ifndef _OPTPROBLEM_H
#define _OPTPROBLEM_H

#include "ad.h"

class COptProblem {
    protected:
	bool opt_init;
    public:
	CVec alfa;
	CVar J;
	
	/** Define sizes for the problem.  */
	virtual void  getProblemSizes (	int *  const  n,         /*-- NUMBER UNKNOWNS */
                    			int *  const  m,         /*-- NUMBER CONSTRAINTS */
                    			int *  const  nnzJ,      /*-- JACOBIAN NONZEROES */
                    			int *  const  nnzH) = 0; /*-- HESSIAN NONZEROES */

	/** Load KNITRO arrays for the problem definition.
	 *  The function assumes array memory has been allocated to match
	 *  the problem sizes. */
	virtual void  getProblemData (	int    * const  objType,       /*-- SCALAR */
	                    		int    * const  objGoal,       /*-- SCALAR */
	                    		double * const  xLoBnds,       /*-- ARRAY LENGTH n */
    	                		double * const  xUpBnds,       /*-- ARRAY LENGTH n */
        	            		double * const  xInitial,      /*-- ARRAY LENGTH n */
                	    		int    * const  cType,         /*-- ARRAY LENGTH m */
                    			double * const  cLoBnds,       /*-- ARRAY LENGTH m */
                    			double * const  cUpBnds,       /*-- ARRAY LENGTH m */
	                    		int    * const  jacIndexVars,  /*-- ARRAY LENGTH nnzJ */
    	                		int    * const  jacIndexCons,  /*-- ARRAY LENGTH nnzJ */
        	            		int    * const  hessRows,      /*-- ARRAY LENGTH nnzH */
                	    		int    * const  hessCols) = 0; /*-- ARRAY LENGTH nnzH */

	/** Compute the function and constraint values at x. */
	virtual double  computeFC (const double * const  x, double * const  c) { return 0; };

	/** Compute the function and constraint first derivatives at x. */
	virtual void  computeGA (const double * const  x, double * const  objGrad, double * const  jac) = 0;

	/** Compute the Hessian of the Lagrangian at x and lambda. */
	virtual void  computeH (const double * const  x, const double * const  lambda, double * const  hess) = 0;

	/** Compute the Hessian of the Lagrangian times vector at x and lambda.
	 *  Return the result in vector. */
	virtual void  computeHV (const double * const  x, const double * const  lambda, double * const  vector) = 0;

	virtual void evalJ() = 0;
	virtual void evalGJ(double* GJ) = 0;

/*	int callbackEvalFCorGA(const int evalRequestCode, const int n, const int m, const int nnzJ, const int nnzH,
                         const double* const x, const double* const lambda, double* const obj, double* const c,
                         double* const objGrad, double* const jac, double* const hessian, double* const hessVector, void* userParams);
	int callbackEvalHess(const int evalRequestCode, const int n, const int m, const int nnzJ, const int nnzH,
                       const double* const x, const double* const lambda, double* const obj, double* const c, double* const objGrad,
                             double* const jac, double* const hessian, double* const hessVector, void* userParams);
*/	int solve();
	
	virtual ~COptProblem() {};
};



#endif

